package map;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.util.*;

/**
 * @Author wangzhipeng
 * @Date 2020-08-13 9:24 上午
 * @Description
 */
public class Demo1 {
        @Test
        public void test1(){
            Map<String,String> map = new HashMap<>();
            map.put("1","11");
            map.put("2","22");
            String s =JSONObject.toJSONString(map);
            System.out.println(s);

            


            //三种遍历

            //键值对遍历
            Set<Map.Entry<String,String>> entrySet = map.entrySet();
            Iterator<Map.Entry<String,String>> iterator = entrySet.iterator();
            while (iterator.hasNext()){
                Map.Entry<String,String> next = iterator.next();
                System.out.println(next.getKey()+" "+next.getValue());
            }

            // value值的遍历
            Collection<String> values = map.values();
            for(String value : values) {
                System.out.println(value);
            }

            //set集合遍历
            for (String key : map.keySet()) {
                String value = map.get(key);
                System.out.println(key + " = " + value);
            }

        }
}
